<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>编辑场馆</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 600px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            margin-bottom: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            color: #666;
        }
        input[type="text"],
        input[type="number"],
        textarea {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        textarea {
            height: 100px;
            resize: vertical;
        }
        .btn {
            display: inline-block;
            padding: 8px 15px;
            background-color: #4CAF50;
            color: white;
            text-decoration: none;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .btn:hover {
            background-color: #45a049;
        }
        .btn-cancel {
            background-color: #f44336;
            margin-left: 10px;
        }
        .btn-cancel:hover {
            background-color: #d32f2f;
        }
        .venue-image {
            max-width: 200px;
            max-height: 200px;
            margin-bottom: 10px;
        }
        .info-text {
            color: #666;
            font-size: 0.9em;
            margin-top: 5px;
        }
        .nav-right {
            float: right;
        }
        .logout-btn {
            background-color: #dc3545;
            color: white;
            padding: 8px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
        }
        .logout-btn:hover {
            background-color: #c82333;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>编辑场馆</h1>
            <div class="nav-right">
                <span style="margin-right: 15px;">欢迎，${sessionScope.user.username}</span>
                <a href="${pageContext.request.contextPath}/user/logout" class="logout-btn">退出登录</a>
            </div>
        </div>
        <form action="${pageContext.request.contextPath}/venue/edit" method="post" enctype="multipart/form-data">
            <input type="hidden" name="id" value="${venue.id}">
            <div class="form-group">
                <label for="name">场馆名称</label>
                <input type="text" id="name" name="name" value="${venue.name}" required>
            </div>
            <div class="form-group">
                <label for="location">位置</label>
                <input type="text" id="location" name="location" value="${venue.location}" required>
            </div>
            <div class="form-group">
                <label for="description">描述</label>
                <textarea id="description" name="description">${venue.description}</textarea>
            </div>
            <div class="form-group">
                <label for="capacity">容量</label>
                <input type="number" id="capacity" name="capacity" value="${venue.capacity}" required min="1">
            </div>
            <div class="form-group">
                <label>当前图片</label>
                <c:if test="${not empty venue.imagePath}">
                    <img src="${pageContext.request.contextPath}${venue.imagePath}" 
                         alt="${venue.name}" class="venue-image">
                </c:if>
            </div>
            <div class="form-group">
                <label for="image">更换图片</label>
                <input type="file" id="image" name="image" accept="image/*">
                <img id="preview" class="venue-image" style="display: none;">
            </div>
            <div class="form-group">
                <label>状态</label>
                <div class="info-text">
                    当前状态：${venue.status == 'available' ? '可用' : '维护中'}
                    <a href="${pageContext.request.contextPath}/venue/updateStatus/${venue.id}?status=${venue.status == 'available' ? 'maintenance' : 'available'}" 
                       class="btn status-btn">
                        ${venue.status == 'available' ? '设为维护' : '设为可用'}
                    </a>
                </div>
            </div>
            <div class="form-group">
                <label>创建时间</label>
                <div class="info-text">
                    <fmt:formatDate value="${venue.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                </div>
            </div>
            <div class="form-group">
                <button type="submit" class="btn">保存</button>
                <a href="${pageContext.request.contextPath}/venue/list" class="btn btn-cancel">取消</a>
            </div>
        </form>
    </div>
    
    <script>
        document.getElementById('image').addEventListener('change', function(e) {
            const preview = document.getElementById('preview');
            const file = e.target.files[0];
            const reader = new FileReader();
            
            reader.onload = function(e) {
                preview.src = e.target.result;
                preview.style.display = 'block';
            }
            
            if (file) {
                reader.readAsDataURL(file);
            }
        });
    </script>
</body>
</html> 